---
layout: default
title: Flexbox Grid Demo
description: A demo of Shuffle with a flexbox grid from Bootstrap 4.
image: /demos/flexbox-grid.jpg
externalCSS: [ "https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" ]
extraJS: [ "demos/padding-grid.js" ]
prism: true
photoCredit: false
---
<style>
  /* Allow bootstrap grid elements to fit on mobile */
  @media (max-width: 575px) {
    .row > [class*="col-"] {
      padding-left: 8px;
      padding-right: 8px;
    }
  }
</style>

<div class="container">
  <div class="row">
    <div class="col-12">
      <h2>Shuffle with Flexbox (Bootstrap 4)</h2>
      <p>On this page, I have added the minified bootstrap css file from the <a href="https://www.bootstrapcdn.com/">Bootstrap CDN</a> (which is also why some of the site-styles are being overriden).</p>
      <p>The <a href="https://getbootstrap.com/docs/4.0/layout/grid/">Bootstrap 4 grid</a> system uses flexbox with padding for gutters.</p>
      <p>The best way to handle this is to have the shuffle container element (<code>#grid</code> in this case), to be a <code>.row</code> so that all the shuffle items remain flex-items.</p>
      <p class="mb-0">If you cannot make the shuffle container element a <code>.row</code>, you will need to set a <code>width</code> for each column (like <code>width: 25%;</code>).</p>
    </div>
  </div>
</div>


<div class="container mb-4">
  <div id="grid" class="my-shuffle-container row">
    {% for i in (1..20) %}
      <div class="grid__brick mt-3 col-6 col-md-4 col-xl-3">
        <div class="card {% cycle 'bg-primary text-white', 'bg-success text-white', 'bg-info text-white', 'bg-warning text-white', 'bg-danger text-white', 'border-primary', 'border-success', 'border-info', 'border-warning', 'border-danger' %}">
          <div class="card-body">{% cycle
            'Return on investment product management equity crowdfunding stock pivot innovator sales ownership.',
            'Founders ecosystem hackathon product management lean startup MVP.',
            'Traction bandwidth MVP direct mailing partner network gen-z growth hacking crowdsource channels responsive web design pivot.',
            'Conversion technology long tail influencer analytics rockstar market seed money.',
            'Investor bandwidth equity ecosystem vesting period client social media.',
            'Angel investor niche market client churn rate crowdsource infrastructure paradigm shift marketing prototype.'
           %}</div>
        </div>
      </div>
    {% endfor %}
    <div class="col-1 my-sizer-element"></div>
  </div>
</div>

<div class="container mb-4">
  <div class="row">
    <div class="col-12">
      <p>The one change I've made to the grid is to allow grid columns to fit on mobile.</p>
      <p>By default, bootstrap 4 grid gutters are 30px, even on mobile, and they use as 12 column grid. At 320px, each column would need to be 26.667px for 12 columns to fit, but since there is 30px of inner gutter, the columns are always >= 30px, so they don't fit for us.</p>
      <p>If you're using Bootstrap's sass files, you can customize the gutter width via the <code>$grid-gutter-widths</code> map. In this example, I'm overriding it instead.</p>
      <div class="code-block">
        <pre rel="CSS"><code class="language-css">@media (max-width: 575px) {
  .row > [class*="col-"] {
    padding-left: 8px;
    padding-right: 8px;
  }
}</code></pre>
      </div>
    </div>

  </div>

</div>

<div class="container">
  <div class="row">
    <div class="col-12">
      <h2>Source code for this demo</h2>
      <p>Link to <a href="{{ site.baseurl }}/js/demos/padding-grid.js">demo source</a></p>
    </div>
  </div>
</div>

<div class="container">
  <div class="row">
    <div class="col-12">
      <h2>Shuffle.js</h2>
      <p>{{ site.longDescription }}</p>
    </div>
  </div>
</div>
